//
//  takePhotoTestViewController.m
//  carcareIOS
//
//  Created by 王然 on 16/7/26.
//  Copyright © 2016年 chezheng. All rights reserved.
//

#import "TakePhotoTestViewController.h"
#import "UploadView.h"
#import "UploadStatusView.h"
#import "TakePhotoMgr.h"

@interface TakePhotoTestViewController ()

@property (nonatomic , strong) UploadView * uploadView;

@property (nonatomic , strong) UploadStatusView * stateView;

@end

@implementation TakePhotoTestViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"拍照验证";
    __weak __typeof(self) wself = self;
    [self navSetupLeftTitle:@"取消" action:^{
        [wself dismissViewControllerAnimated:YES completion:nil];
    }];

    self.uploadView = [[UploadView alloc]initWithUploadLicenseName:@"*证件信息仅限于车辆投保使用，请放心上传" andDescripeDetail:@"点击添加" addImageName:@"insuUploadPhotoImage" uploadBtnTitle:@"马上验证"];
    self.uploadView.addbuttonClick = ^(UIButton * sender)
    {
        [wself addBtnClick];
    };
    
    //uploadErrorImage  uploadingImage  uploadSuccessImage
    self.stateView = [[UploadStatusView alloc]initWithFrame:CGRectMake(0, 0, __MAIN_WIDTH - 60 * __MAIN_RATIO_375 * 2, 138 * __MAIN_RATIO_375) withImageName:@"uploadingImage" withTitle:@"正在上传..."];
    
    self.uploadView.commitbuttonClick = ^ (UIButton * sender)
    {
        
        [AlertMgr showView:wself.stateView];
        [TAKEPHOTOMGR uploadPictureType:@"policy" withNetSuccess:^(id JSON) {
            [wself.stateView changeImageName:@"uploadSuccessImage" withTitle:@"上传成功"];
            [NSTimer scheduledTimerWithTimeInterval:1 block:^{
                [AlertMgr dismiss:TYPE_VIEW_ALERT];
                
                // 在这里进行界面跳转 ，跳转的url
                [wself dismissViewControllerAnimated:YES completion:^{
                    if (wself.UploadSuccess) {
                        wself.UploadSuccess(JSON[@"info"]);
                    }
                }];
                
            } repeats:NO];
            
        } fail:^(id JSON) {
            [wself.stateView changeImageName:@"uploadErrorImage" withTitle:@"上传失败，请重新上传"];
            [NSTimer scheduledTimerWithTimeInterval:3 block:^{
                [AlertMgr dismiss:TYPE_VIEW_ALERT];
                
            } repeats:NO];
            
        }];
        
        [NSTimer scheduledTimerWithTimeInterval:10 block:^{
            [AlertMgr dismiss:TYPE_VIEW_ALERT];
            
        } repeats:NO];
        
    };
    [self.view addSubview:self.uploadView];
    
    [self resetTableView];

}
#pragma mark - addBtnClick添加照片按钮
- (void)addBtnClick
{

     __weak __typeof(self) wself = self;
    [TAKEPHOTOMGR selectActionPictureWithController:self callBack:^(UIImage * backImage) {
        wself.uploadView.upImage = backImage;
    }];
    
}
- (void)resetTableView
{
    [self.tableView setFrame:CGRectMake(0, 0 , __MAIN_WIDTH, 0)];
    self.tableView.backgroundColor = [Theme backGroundColor];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
